import {defineStore} from 'pinia'

interface UserInfo {

}

interface UserState {
    token: string;
    info: UserInfo | null
}

export const useUserStore = defineStore('storeUser', {
    state: (): UserState => ({
        token: '',
        info: null
    }),
    actions: {
        setToken(_token: string) {
            this.token = _token
        },
        setInfo() {
            
        },
        logout() {
            this.$reset()
        }
    },
    // 使用该插件，开启数据缓存
    persist: {
        enabled: true,
        strategies: [
            {storage: sessionStorage, paths: ['token']}, // firstName 和 lastName字段用sessionStorage存储
            {storage: localStorage, paths: []}, // accessToken字段用 localstorage存储
        ],
    },
})
